    function showPupUp(show, tipo) {

        var back = document.getElementById("backgrounddiv");
        var box = document.getElementById("popUpdiv");
        
        var editor = nivelSelected;
        
        if(tipo == "Agregar")
        {
            editor++;
        }
        

        
        var edit_add_popUp = document.getElementById("edit_add_popUp_" + editor);
        edit_add_popUp.style.display = "block";
        edit_add_popUp.style.visibility = "visible";
        
        var titulo = document.getElementById("titulo_popUp");
        titulo.textContent = tipo;
                
        if (show)
        {
            box.style.display = "block";
            back.style.display = "block";    
        }
        else{
            box.style.display = "none";
            back.style.display = "none";  
        }
    
    }

var nivelSelected = 0;

 function click(e) {

  if (navigator.appName == 'Netscape'
           && e.which == 3) {
      getMouseXY(e);
      return false;
      
      }
   else {
      if (navigator.appName == 'Microsoft Internet Explorer'
          && event.button==0)
          getMouseXY(event);
         return false;
         }
       
   return true;

}

function clear(e) {
    var menu = document.getElementById("rightClickMenu");
    menu.style.display = "none";
}

document.onmouseup = clear;
document.oncontextmenu = click;

function zoneFalse() {
    TreeView_UnhoverNode(this);
    zona = false;
}

function zoneTrue() {

    if (this.className.indexOf("TreeView1_6") >= 0)
        zona = true;
    TreeView_HoverNode(TreeView1_Data, this);
}

var zona = false;

 // Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

function setSelected() {

    var tree = document.getElementById("TreeView1");
    var total = tree.getElementsByTagName("A");
    var i = 0;
    while (total[i] != null) 
    {
        if (total[i].id.indexOf("TreeView1t") >= 0)
        {
            total[i].parentNode.onmouseover = zoneTrue;
            total[i].parentNode.onmouseout = zoneFalse;
        }
        i++;
    }
}


// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {

    var elem;
    
  if (navigator.appName == 'Microsoft Internet Explorer') 
  { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
    elem = event.srcElement;
  }
  else 
  {  // grab the x-y pos.s if browser is NS
    elem = e.originalTarget;
    tempX = e.pageX;
    tempY = e.pageY;
  }


    if (zona) 
    {
        var lvl = 0;
        var hijos = false;
        
        while (elem.id != 'TreeView1')
        {
            if (elem.tagName == 'DIV')
            {
                lvl++;
            }
            if (elem.tagName == 'TABLE' && elem.nextSibling && elem.nextSibling.tagName == 'DIV')
            {
                hijos = true;
            }
            elem = elem.parentNode;
        }

        nivelSelected = lvl;

        var menu = document.getElementById("rightClickMenu");

        if (nivelSelected == 5 || nivelSelected == 4 && hijos) 
        {
           var agregarButton = document.getElementById("AgregarHijo");
           agregarButton.style.display = "none";
           agregarButton.style.visibility = "hidden";
         }
         

            
        menu.style.top = tempY + "px";
        menu.style.left = tempX + "px";
        menu.style.display = "block";

        if (nivelSelected == 0) 
        {
            var EditarButton = document.getElementById("Editar");
            EditarButton.style.display = "none";
            EditarButton.style.visibility = "hidden";

            var BorrarButton = document.getElementById("Borrar");
            BorrarButton.style.display = "none";
            BorrarButton.style.visibility = "hidden";  
        }
        

    }
}
